package com.slipper.system.role.service;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;

import com.slipper.system.role.bo.RolePrivilegeBO;
import com.slipper.system.role.dao.RolePrivilegeDao;
import com.slipper.util.Tool;
import com.slipper.util.UUID;
import org.springframework.stereotype.Service;
import jakarta.annotation.Resource;
import com.slipper.core.transaction.ReadTransactional;
import com.slipper.core.transaction.WriteTransactional;

import java.util.List;

@Service
@ReadTransactional
public class RolePrivilegeService {
    @Resource
    private RolePrivilegeDao rolePrivilegeDao;
    
    public RolePrivilegeBO queryBy(String id) {
        return rolePrivilegeDao.queryBy(id);
    }
    
    public List<RolePrivilegeBO> queryList(RolePrivilegeBO bo) {
        return rolePrivilegeDao.queryList(bo);
    }
    
    public PageInfo<RolePrivilegeBO> queryPage(RolePrivilegeBO bo) {
        PageHelper.startPage(bo.getPageNumber(), bo.getPageSize());
        return new PageInfo<>(rolePrivilegeDao.queryList(bo));
    }
    
    @WriteTransactional
    public int save(RolePrivilegeBO bo) {
        if (Tool.isNotBlank(bo.getId())) {
            return rolePrivilegeDao.update(bo);
        } else {
            bo.setId(UUID.getUUID());
            return rolePrivilegeDao.insert(bo);
        }
    }
    
    @WriteTransactional
    public int delete(RolePrivilegeBO bo) {
        return rolePrivilegeDao.delete(bo);
    }
}
